﻿using System;
using System.IO;
using HtmlDeploy;
using Microsoft.Build.Utilities;

namespace HtmlDeployTask
{
    public class HtmlDeploy : Task
    {
        public string TemplatePath { get; set; }
        public string Path { get; set; }
        public string MasterPagePath { get; set; }
        public string ViewPath { get; set; }

        public override bool Execute()
        {
            if (!string.IsNullOrEmpty(MasterPagePath) && !string.IsNullOrEmpty(ViewPath))
            {
                // create a writer and open the file
                using (TextWriter tw = new StreamWriter("date.txt"))
                {
                    tw.WriteLine(DateTime.Now);
                }

                var srcs = (new MasterPage(MasterPagePath, ViewPath)).Compile();

                foreach (var src in srcs)
                {
                    using (var sw = new StreamWriter(Path + src.Key + "compiled"))
                        sw.WriteLine(src.Value);
                }
            }
            
            return true;
        }
    }
}
